"""
构建一个用户注册系统
UserRepository：负责与数据库交互
EmailService：发送邮件
RegistrationService：处理用户注册逻辑，依赖上面两个组件
"""

from abc import ABC,abstractmethod


class UserRepository(ABC):
    @abstractmethod
    def save(self, user):
        pass

    @abstractmethod
    def find_by_email(self, email):
        pass

class EmailService(ABC):
    @abstractmethod
    def send(self, email,message):
        pass


class RegistrationService:
    def __init__(self, user_repo:UserRepository, email_service: EmailService):
        self.user_repo = user_repo
        self.email_service = email_service

    def register_user(self,user):
        self.user_repo.save( user)
        self.email_service.send(user['email'],'Welcome to your platform')
        return f'user {user['user']} registered successfully'